mysql纯文本格式备份的shell脚本
所谓的mysql纯文本格式数据,是在数据表中没有insert into这样的查询sql语句的存在,而只有类似如下:
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
'123','xxx','xxx','xxx'
的纯数据结构。
此种备份方式,可以节约很多存储空间。
不过此种备份的难度也要比传统的mysqldump要大。
本文以mysql数据库中的test数据库为例子,用shell脚本实现这种备份。
用到的shell 脚本,代码如下:
复制代码 代码示例:
#!/bin/bash
tables=`sudo /Applications/XAMPP/xamppfiles/bin/mysql -uroot -p test -e 'show tables'`
echo $tables
for i in $tables
do
if [ $i = 'Tables_in_test' ]
then
continue
fi
sudo /Applications/XAMPP/xamppfiles/bin/mysqldump -uroot -l -T /tmp/ test $i --fields-enclosed=\" --fields-terminated-by=,
done
执行脚本,即可把mysql数据和sql文件全部备份到/tmp/目录。
以下是恢复备份的shell 脚本,代码如下:
#!/bin/bash
sqlList=`ls /tmp/*.sql`
txtList=`ls /tmp/*.txt`
for i in $sqlList
do
sudo /Applications/XAMPP/xamppfiles/bin/mysql -uroot test < $i
done
for i in $txtList
do
sudo /Applications/XAMPP/xamppfiles/bin/mysqlimport --user=root test --fields-enclosed-by=\" --fields-terminated-by=, $i
done
注意:
恢复时要把sql文件和txt分别导入进来,先把所有的sql文件导入进来,然后再导入数据文件txt即可。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/shell/11782.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Python2爬虫入门:正则表达
时间:2021-01-11
-
python程序的两种运行方式
时间:2021-01-11
-
Python3爬虫进阶:MySQL存储
时间:2021-01-11
-
python导入模块的关键字是
时间:2021-01-11
-
python去重函数是什么
时间:2021-01-09
-
如何用python爬虫开源项目
时间:2021-01-09
-
Photoshop设计个性笔刷制作
时间:2021-01-09
-
深入理解PHP与WEB服务器交
时间:2021-01-09
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
php如何接收json数据
时间:2021-01-08
-
php ucwords函数怎么用
时间:2021-01-08
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
python中pow什么意思
时间:2021-01-08
-
如何在python数据挖掘使用pandas包?
时间:2021-01-09
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
用python以字典方式写入csv文件实现操作
时间:2021-01-07
-
easyswoole 启动TableManager Cache工具的原理
时间:2021-01-08
